Completed
Push — master ( e193d1...415e1b )
by Justin
01:32
created

module.exports   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
c 1
b 0
f 0
nc 3
nop 1
dl 0
loc 14
rs 9.4285
1
module.exports = function(GedcomX){
2
3
  var utils = require('../utils'),
4
      AtomCommon = require('./AtomCommon');
5
  
6
  /**
7
   * The content of an entry.
8
   * 
9
   * @constructor
10
   * @param {Object} [json]
0 ignored issues
show
Documentation introduced by
The parameter [json] does not exist. Did you maybe forget to remove this comment?
Loading history...
11
   */
12
  var AtomContent = function(json){
13
    
14
    // Protect against forgetting the new keyword when calling the constructor
15
    if(!(this instanceof AtomContent)){
16
      return new AtomContent(json);
17
    }
18
    
19
    // If the given object is already an instance then just return it. DON'T copy it.
20
    if(AtomContent.isInstance(json)){
21
      return json;
22
    }
23
    
24
    this.init(json);
0 ignored issues
show
Best Practice introduced by
There is no return statement in this branch, but you do return something in other branches. Did you maybe miss it? If you do not want to return anything, consider adding return undefined; explicitly.
Loading history...
25
  };
26
  
27
  AtomContent.prototype = Object.create(AtomCommon.prototype);
28
  
29
  AtomContent._gedxClass = AtomContent.prototype._gedxClass = 'GedcomX.AtomContent';
30
  
31
  AtomContent.jsonProps = [
32
    'gedcomx'
33
  ];
34
  
35
  /**
36
   * Check whether the given object is an instance of this class.
37
   * 
38
   * @param {Object} obj
39
   * @returns {Boolean}
40
   */
41
  AtomContent.isInstance = function(obj){
42
    return utils.isInstance(obj, this._gedxClass);
43
  };
44
45
  /**
46
   * Initialize from JSON
47
   * 
48
   * @param {Object}
0 ignored issues
show
Documentation introduced by
The parameter * does not exist. Did you maybe forget to remove this comment?
Loading history...
49
   * @return {AtomContent} this
50
   */
51
  AtomContent.prototype.init = function(json){
52
    
53
    AtomCommon.prototype.init.call(this, json);
54
    
55
    if(json){
56
      this.setGedcomX(json.gedcomx);
57
    }
58
    return this;
59
  };
60
  
61
  /**
62
   * Set the GedcomX object
63
   * 
64
   * @param {GedcomX} gedcomx
65
   * @return {AtomContent} this
66
   */
67
  AtomContent.prototype.setGedcomX = function(gedcomx){
68
    if(gedcomx){
69
      this.gedcomx = GedcomX(gedcomx);
70
    }
71
    return this;
72
  };
73
  
74
  /**
75
   * Get the GedcomX object
76
   * 
77
   * @return {GedcomX}
78
   */
79
  AtomContent.prototype.getGedcomX = function(){
80
    return this.gedcomx;
81
  };
82
  
83
  /**
84
   * Export the object as JSON
85
   * 
86
   * @return {Object} JSON object
87
   */
88
  AtomContent.prototype.toJSON = function(){
89
    return this._toJSON(AtomCommon, AtomContent.jsonProps);
90
  };
91
  
92
  GedcomX.AtomContent = AtomContent;
93
94
};